// const { set } = require("lodash");

let obj = {
  name: 'lanpang',
  age: 18
}

let proxyObj = new Proxy(obj, {
  // target 就是Proxy代理的对象 也就是 obj
  // property 是当前访问的key
  get(target, property) { // 监视obj中数据的访问
    // console.log(111);
    // console.log(target);
    // console.log(property);
    // return 111; // get的返回值就是获取proxyObj属性得到的值
    // 例如 如果返回111 那么 proxyObj.name = 111 && proxyObj.age = 111 && proxyObj.anything = 111;
    return property in target ? target[property] : undefined;
  },
  // set用作监听对象中成员的改变
  // value 是要设置的值 
  set(target, property, value) {
    // console.log(target);
    // console.log(property);
    // console.log(value);
    target[property] = value;
  },
  deleteProperty(target, property) {
    console.log('delete', property);
    delete target[property];
  }
})

proxyObj.sex = 'man';

delete proxyObj.age;
console.log(obj)

const arr = [1, 2, 3, 4, 5];
const proxyArr = new Proxy(arr, {
  set(target, property, value) {
    console.log(target);
    console.log(property);
    console.log(value);
    target[property] = value;
    return true;
  }
});

// proxyArr.push(111, 222);
// console.log(arr); 

Object.defineProperty(obj, 'name', {
  get() {
    console.log('name 被访问');
    return obj._name;
  }
})

const a = obj.name;
console.log(a);